import consts from './consts.js'

function setToken(value) {
  wx.setStorageSync(consts.tokenName, value)
}
function getToken() {
  return wx.getStorageSync(consts.tokenName)
}
function delToken() {
  wx.removeStorageSync(consts.tokenName)
}
function setAdminToken(value) {
  wx.setStorageSync(consts.adminTokenName, value)
}
function getAdminToken() {
  return wx.getStorageSync(consts.adminTokenName)
}
function delAdminToken() {
  wx.removeStorageSync(consts.adminTokenName)
}
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime,
  setToken: setToken,
  getToken: getToken,
  delToken: delToken,
  setAdminToken: setAdminToken,
  getAdminToken: getAdminToken,
  delAdminToken: delAdminToken
}
